<template>
  <div class="slide-small-container">
    <ul class="slide-nav-wrap">
      <li
        v-for="(item, index) in list"
        :key="item.id"
        class="slide-nav-item"
        :class="{ active: curIndex === index }"
        @click="handleSlideItemClick(item, index)"
      >
        <span v-html="formatName(item.name)"></span>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  name: 'slideNav',
  props: {
    list: {
      type: Array,
      default: () => []
    },
    curActiveIndex: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      curIndex: this.curActiveIndex || 0
    };
  },
  watch: {
    curActiveIndex(newVal) {
      this.curIndex = newVal;
    }
  },
  methods: {
    formatName(oldName) {
      let str = oldName;
      if (str.length > 3 && str.length < 6) {
        const str1 = str.slice(0, 2);
        const str2 = str.slice(2);
        str = str1 + '<br />' + str2;
      }
      return str;
    },
    handleSlideItemClick(item, i) {
      this.curIndex = i;
      this.$emit('changeNavTab', i, item.name);
    }
  }
};
</script>

<style lang="scss" scoped>
.slide-small-container {
  width: 70px;
  height: 100vh;
  overflow: scroll;
  -webkit-overflow-scrolling: touch;
}
.slide-nav-wrap {
  width: 50px;
  border-radius: 0 6px 6px 0;
  background-color: #000;
  overflow: hidden;
  height: auto;

  .slide-nav-item {
    width: 50px;
    min-height: 65px;
    padding: 0 7px;
    box-sizing: border-box;
    color: #fff;
    font-size: 12px;
    line-height: 14px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    word-wrap: break-word;
    word-break: break-all;
    text-align: center;
  }
  .active {
    background-color: #ff1010;
    &:after {
      content: '';
      display: block;
      width: 3px;
      height: 32px;
      border-radius: 3px;
      background: #fff;
      position: absolute;
      left: 0;
      top: 50%;
      margin-top: -16px;
    }
  }
}
</style>
